using System;
using System.Web.UI.WebControls;
using System.Collections;
using ScenarioFramework.Modules;
using ScenarioFramework.Modules.DM.DataModel;
using ScenarioFramework.Modules.FormHelper;
using System.Web.UI;
using ScenarioFramework.Portal;
using ScenarioFramework.Portal.Modules.Menu;
using System.Collections.Generic;

namespace SFPortal.UserControls
{
	public partial class PageTabs : System.Web.UI.UserControl
	{
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}
		#endregion

		public string CurrentTabName;
        public string CurrentSubTabName;

		protected void Page_Load(object sender, System.EventArgs e) 
		{
			MenuHelper menuHelper = (MenuHelper)Session["MenuHelper"];

            ScenarioFramework.Portal.Modules.Menu.BO.Menu currentMenu = null;
            
            PlaceHolder1.Controls.Add(new LiteralControl("<ul class=\"main\">"));
            bool bFirstChild = true;
            foreach (ScenarioFramework.Portal.Modules.Menu.BO.Menu menu in menuHelper.RootMenu.Menu)
			{
                bool fAHREF = true;
                if (String.Compare(CurrentTabName, menu.Name) == 0)
                {
                    PlaceHolder1.Controls.Add(new LiteralControl("<li class=\"current\">"));
                    fAHREF = false;
                    currentMenu = menu;
                }
                else if (bFirstChild)
                {
                    bFirstChild = !bFirstChild;
                    PlaceHolder1.Controls.Add(new LiteralControl("<li class=\"first-child\">"));
                }
                else
                {
                    PlaceHolder1.Controls.Add(new LiteralControl("<li>"));
                }

                if (fAHREF)
                {
                    PlaceHolder1.Controls.Add(new LiteralControl("<a href=\""));
                    PlaceHolder1.Controls.Add(new LiteralControl(menu.Url));
                    PlaceHolder1.Controls.Add(new LiteralControl("\">"));
                }
                
                PlaceHolder1.Controls.Add(new LiteralControl("<span>"));
                PlaceHolder1.Controls.Add(new LiteralControl(menu.Name));
                PlaceHolder1.Controls.Add(new LiteralControl("</span>"));

                if (fAHREF)
                    PlaceHolder1.Controls.Add(new LiteralControl("</a>"));
                
                PlaceHolder1.Controls.Add(new LiteralControl("</li>"));
			}

            PlaceHolder1.Controls.Add(new LiteralControl("</ul>"));

            PlaceHolder1.Controls.Add(new LiteralControl("<ul class=\"sub\">"));

            //foreach (SFMenu menu in currentMenu.Menus)
            foreach (ScenarioFramework.Portal.Modules.Menu.BO.Menu menu in currentMenu.Menus)
            {
                if (menu.Type == ScenarioFramework.Portal.Modules.Menu.BO.MenuType.Separator )
                {
                }
                else if (menu.Id.CompareTo(CurrentSubTabName) == 0)
                {
                    PlaceHolder1.Controls.Add(new LiteralControl("<li>"));
                    PlaceHolder1.Controls.Add(new LiteralControl(menu.Name));
                    PlaceHolder1.Controls.Add(new LiteralControl("</li>"));
                }
                else
                {
                    PlaceHolder1.Controls.Add(new LiteralControl("<li><a href=\""));
                    PlaceHolder1.Controls.Add(new LiteralControl(menu.Url) );
                    PlaceHolder1.Controls.Add(new LiteralControl("\">"));
                    PlaceHolder1.Controls.Add(new LiteralControl(menu.Name));
                    PlaceHolder1.Controls.Add(new LiteralControl("</a></li>"));
                }
            }

            PlaceHolder1.Controls.Add(new LiteralControl("</ul>"));

    	}
	}
}
